home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / vbpoint.zip / VBPOINT.TXT < prev   
Text File  |  1991-10-03  |  4KB  |  76 lines

  1. VBPOINT.LL
  2. by Jonathan Zuck
  3. Copyright 1991 User Friendly, Inc.
  4. "You are hereby granted liscence to use and distribute this DLL along with
  5. your software. If you distribute the DLL and API to other programers, you
  6. must distribute it with *at least* all of the files in this ZIP file:
  7.  
  8. VBPOINT.DLL    The DLL for pointer support
  9. VBPOINT.MAK    The VB MAK file for the demo
  10. VBPOINT.FRM    The VB form for the demo
  11. VBPOINT.TXT    This DOC file
  12.  
  13. As long as this condition is met, you owe no restitution to UFI."
  14.  
  15. What is VBPOINT.DLL?
  16. This is a dynamic link library, written in Turbo Pascal for Windows that
  17. adds some much needed pointer support to Visual Basic. There are two
  18. exported routines in VBPoint: LP2Str$ and Str2LP.
  19.  
  20. LP2Str$ is a string function that copies data, pointed to by a so-called
  21. "Long Pointer" into a Visual Basic proprietary string variable.  In many
  22. instances the long pointer will be the pointer to a null-terminated string
  23. and many DLLs return this sort of string in their exported functions.
  24. However, you are by no means limited to string data. This might be a pointer
  25. to global memory, an integer or an record variable array. Here lies the
  26. solution to the missing keywords: MK? and BSAVE.
  27.  
  28. Str2LP is a subroutine that will copy data from one address to another. With
  29. this function you can create the CV? and BLOAD commands.
  30.  
  31. When am I passing a long pointer?
  32. In VB you are passing a long pointer to a DLL routine when pass a string
  33. variable, using the ByVal keyword and when you pass any other variable
  34. type without it.  This includes passing a record variable or the first
  35. element of a numeric array.
  36.  
  37. In a Windows DLL API, you are using a long pointer anytime the variable
  38. type that is specified begins with the letters 'LP' such as LPSTR, LPVOID
  39. etc. A number of DLLs return long pointers in their functions.  Two that
  40. come to mind in the Windows API are GetDosEnvironment which returns the
  41. address of the environment table and GlobalLock which locks an area of
  42. global memory.
  43.  
  44. The environment table is an example of one type of string array used in C.
  45. It is one contiguous blob of memory with each variable separated by a NULL.
  46. This sort of array is popular in network APIs.  So, even though you have
  47. the ENVIRON$ function in VB, it is instructive to see how to walk through
  48. one of these sorts of arrays.  One of the most powerful things about these
  49. functions is that you can simply add to the LONG variable and you will
  50. be pointing further into memory. This is the technique used in the example.
  51.  
  52. Through a combination of GlobalAlloc and GlobalLock, you could easily
  53. mimic the functionality of HUGEARR.DLL.  All that DLL does is GlobalAlloc
  54. a big chunk of memory and returns the handle to you. When you want to
  55. access an element in the array, the DLL does a GlobalLock on the memory
  56. handle which returns a...that's right class, a long pointer.  The DLL
  57. then calculates the offset into that memory where your data  should go
  58. and you are in business.  For simplicity, let's take the example of a huge
  59. integer array where each element is two bytes:  We want 50,000 elements so
  60. we GlobalAlloc 100,000 bytes. Now we want to insert a value at element
  61. number 10,000 (or byte 20,000).  We GlobalLock the memory handle we got
  62. back with our call to GlobalAlloc and that returns us a long pointer to our
  63. memory chunk.  We then add 20,000 to that pointer and:
  64.  
  65.         Str2LP (MyInt, ByVal NewPointer&, 2)
  66.  
  67. Hopefully you start to see the power of this little function!
  68.  
  69. I hope this was helpful and not too confusing! Eeep!  I will try to do an
  70. even better job of explaining all this in Visual Basic Techniques and
  71. Utilities coming out first quarter next year.  Hope you grab a copy!<g>
  72.  
  73. Jonathan Zuck
  74. October 4, 1991
  75. Washington, DC
  76.